<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>地图路线</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>	

<!--百度地图js-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=7E66AE4c1ed8c45c06b664081777676c"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>

<style type="text/css">
body {
	margin: 0px;
	padding: 0px;
}
.allmap {
	position: fixed;
	width: 100%;
	left: 0px;
	top: 0px;
	right: 0px;
	bottom: 0px;
	background-color: #CCC;
	height: 100%;
}
.close {
	font-size: 12px;
	position: fixed;
	top: 10px;
	right: 10px;
	padding-top: 3px;
	padding-right: 15px;
	padding-bottom: 3px;
	padding-left: 15px;
	background-color: #FFF;
	border: 1px solid #999;
	border-radius: 5px;
	z-index: 100;
}
</style>

<script>
  $(document).ready(function(){
	  $(".allmap").css("height",$(document).height()+"px");
	});
</script>

</head>

<body>

<!--地图-->
<div id="allmap" class="allmap"></div>

<div class="close" onClick="javascript:history.back(-1);">关闭</div>


<!--百度地图API-->
<script type="text/javascript">
    $(function(){ 
       console.log('run getCurrentPosition before');
       navigator.geolocation.getCurrentPosition(translatePoint); //html5定位 
      });
	  
	function translatePoint(position){ 
		var currentLat = position.coords.latitude; 
		var currentLon = position.coords.longitude; 
		var gpsPoint = new BMap.Point(currentLon, currentLat); 
		BMap.Convertor.translate(gpsPoint, 0, initMap); //经纬度转换为百度坐标 
	} 
	
	
    function initMap(point){ 
	   console.log('run this code !!!!!!!!!!!!!!!!!!!!!!!!!');
		//alert(point.lng);
		//初始化地图 
        //var obj = ["http://api.map.baidu.com/geocoder/v2/?output=json&ak=7E66AE4c1ed8c45c06b664081777676c&location=23.03016,113.761543"];
//        	alert(result.formatted_address);
		$.ajax({
             type: "get",
             async: false,
             url: "http://api.map.baidu.com/geocoder/v2/?output=json&ak=7E66AE4c1ed8c45c06b664081777676c&location="+point.lat+","+point.lng+"",
             dataType: "jsonp",
             jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
             jsonpCallback:"json",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名，也可以写"?"，jQuery会自动为你处理数据
             success: function(json){
				var start = json.result.formatted_address; 
				
				<!--地图渲染-->
				map = new BMap.Map("allmap"); 
				map.addControl(new BMap.NavigationControl()); //缩放按钮
				map.addControl(new BMap.ScaleControl()); //标尺
				//map.addControl(new BMap.OverviewMapControl());//小地图
		//		alert(point.lng);//长
		//		alert(point.lat);//短
				
				var end = "${place}";
				map.centerAndZoom(new BMap.Point, 11);
				//三种驾车策略：最少时间，最短距离，避开高速
				var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME,BMAP_DRIVING_POLICY_LEAST_DISTANCE,BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
				map.clearOverlays(); 
				var i=$("#driving_way select").val();
				search(start,end,routePolicy[i]); 	
					
             },
             error: function(){
                 alert('无法定位');
				 window.location.href="/";
             }
         });
		 
	
			
				
				//var start = "东莞市中侨大厦"
				
	}
	
	function search(start,end,route){ 
						var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true},policy: route});
						driving.search(start,end);
					} 
</script>

</body>
</html>
